const api = require("../../../utils/api.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    dqList:[],
    todayList:[],
    otherList:[],
    hidden:true
  },
  //获取当前时间，格式YYYY-MM-DD
  getNowFormatDate:function() {
      var date = new Date();
      var seperator1 = "-";
      var year = date.getFullYear();
      var month = date.getMonth() + 1;
      var strDate = date.getDate();
      if (month >= 1 && month <= 9) {
          month = "0" + month;
      }
      if (strDate >= 0 && strDate <= 9) {
          strDate = "0" + strDate;
      }
      var currentdate = year + seperator1 + month + seperator1 + strDate;
      return currentdate;
  },
  //获取每日一练试卷列表
  getdpExamList:function(that){
    let url = "/dayExam/getDayExamList";
    let userData = wx.getStorageSync("USERDATA");
    let courseInfo = wx.getStorageSync("COURSEINFO");
    let parmas={
      uid:userData.uid,
      sessionid:userData.sessionid,
      courseid:courseInfo.id
    }
    api.sendPosts(url,parmas,function(res){
      // console.log(res);
      that.setData({
        dqList:res.list
      });
      //设置前端数据显示格式
      that.setdqList(that);
    });
  },
  //设置前端数据显示格式
  setdqList:function(that){
    let list = that.data.dqList;
    let date = that.getNowFormatDate();
    let todayList=[];
    let otherList=[];
    let j = 0,m = 0;
    for(let i=0 ; i<list.length; i++){
      list[i].courseTitle = list[i].date+"  "+list[i].courseTitle;
      if(date==list[i].date){
        todayList[j++] = list[i];
      }else{
        otherList[m++] = list[i];
      }
    }
    that.setData({
      todayList:todayList,
      otherList:otherList
    });
  },
  clickItem:async function(options){
    var that = this;
    let option={
      paperid:options.currentTarget.dataset.res.paperid
    };
    let hidden = await api.clickItem(option);
    that.setData({
      hidden:hidden
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    //获取每日一练试卷列表
    that.getdpExamList(that);
    

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})